package com.samapp.indent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

import com.samapp.MyApplication;
import com.samapp.R;
import com.samapp.review.ReviewIndentActivity;

public class IndentDetailsActivity extends Activity implements OnClickListener {

	/** 返回按钮 */
	private Button btnBack = null;
	/** 添加订单明细按钮 */
	private Button btnAddIndent = null;
	/** 上一步 */
	private Button btnFront = null;
	/** 下一步 */
	private Button btnNext = null;
	private ListView listViewIndentDetail = null;
	private IndentDetailAdapter mIndentDetailAdapter;
	private MyApplication myApplication = MyApplication.getApplicationInstance();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_indent_detail);
		init();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mIndentDetailAdapter.notifyDataSetChanged();
	}

	private void init() {
		initView();
		initListView();
		initListener();
	}

	private void initView() {
		btnBack = (Button) findViewById(R.id.btn_back);
		btnAddIndent = (Button) findViewById(R.id.btn_add);
		btnFront = (Button) findViewById(R.id.btn_front);
		btnNext = (Button) findViewById(R.id.btn_next);
		listViewIndentDetail = (ListView) findViewById(R.id.listview_indent_detail);
	}

	private void initListView() {
		mIndentDetailAdapter = new IndentDetailAdapter(IndentDetailsActivity.this, myApplication.newIndent.getOrderDetail());
		listViewIndentDetail.setAdapter(mIndentDetailAdapter);
	}

	private void initListener() {
		btnBack.setOnClickListener(this);
		btnAddIndent.setOnClickListener(this);
		btnFront.setOnClickListener(this);
		btnNext.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			skip(SampleDetailsActivity.class);
			finish();
			break;
		case R.id.btn_add:
			skip(AddIndentDetailsActivity.class);
			break;
		case R.id.btn_front:
			skip(SampleDetailsActivity.class);
			finish();
			break;
		case R.id.btn_next:
			skip(ReviewIndentActivity.class);
			finish();
			break;
		}
	}

	/** 跳转页面 */
	private void skip(Class<?> cls) {
		Intent intent = new Intent(this, cls);
		startActivity(intent);
	}

	/** 修改返回键 */
	@Override
	public void onBackPressed() {
		super.onBackPressed();
		btnFront.performClick();
	}

}
